package es.luimoco.wishlist;

import java.util.ArrayList;

import android.os.Bundle;
import android.app.ListActivity;
import android.content.Intent;
import android.graphics.BitmapFactory;
import android.view.Menu;
import android.view.View;
import android.widget.ImageButton;

public class MainActivity extends ListActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //Obtenemos la lista de titulos
        ArrayList<Wish> wishes = getItems();
        //Entregamos la lista de titulos al adaptador de la lista en el Layout Lista.xml
        setListAdapter(new WishAdapter(this, R.layout.lista_item, wishes));
        
        final ImageButton addWishButton = (ImageButton) findViewById(R.id.bmas);
        addWishButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
            	Intent intent = new Intent(MainActivity.this, AddActivity.class);
		        startActivity(intent);
            }
        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
    
    /*
     * Obtiene una lista de titulos de libros
     *
     * @returns ArrayList<String> titulos de libros
     */
    public ArrayList<Wish> getItems()
    {
        ArrayList<Wish> MiLista = new ArrayList<Wish>();
 
        MiLista.add(new Wish(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher),"titulo1","observacion1"));
        MiLista.add(new Wish(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher),"titulo2","observacion2"));
        MiLista.add(new Wish(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher),"titulo3","observacion3"));
 
        return MiLista;
    }
    
}
